import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/Home.vue'
import menus from './menu'

const routes = [
  {
    path:'/',
    redirect:{name:'Login'}
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    // meta: { title: '首页', icon: 'HomeFilled', top: true },
    children:[
  
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/LoginView.vue')
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/RegisterView.vue')
  },
  //菜单栏动态路由
]

// 动态路由routes
/* function addRoutes(){
   menus.forEach(item=>{
    router.addRoute('home',item)
    // routes[0].children.push(item)
   })
}
addRoutes() */

const router = createRouter({
  history: createWebHistory(),
  routes
})


// 动态路由routes
function addRoutes(){
   menus.forEach(item=>{
    router.addRoute('Home',item)
   })
}
addRoutes()
// 全局路由导航守卫
router.beforeEach((to, from, next) => {
  //  addRoutes()

    // console.log(routes,'1111',router)
    console.log(to,'----路由导航守卫----',from,routes)
    next()
})

export default router